home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Diamond Collection
/
The Diamond Collection (Software Vault)(Digital Impact).ISO
/
cdr47
/
ertimer.zip
/
TIMER.H
< prev
next >
Wrap
C/C++ Source or Header
|
1995-01-01
|
6KB
|
96 lines
/***************************************************************************\
** TIMING CODE MODULE **
**=========================================================================**
** Written by Ethan Rohrer, (c) Nuthing Software, December 4, 1994 **
** **
** Revision History **
** ---------------- **
** Date Description **
** --------- --------------------------------------------------------- **
** 13 May 94 Initial Release **
** 04 Dec 94 Updated code to conform to current coding standards/style **
** Allowed appl. to specify # of timers as param. to TM_Init **
** Standardized error handling with function _TM_Error **
**=========================================================================**
** This file contains the declarations for publicly available types and **
** functions. **
**=========================================================================**
** USING THIS MODULE **
** Before calling any other timing routine, you must call TM_Init(n), **
** where n specifies the number of timers your application needs. **
** It may be a good idea to call TM_Init() in the initialization **
** portion of your application. **
** **
** To begin timing an event, make a call to TM_StartTimer(tid), **
** where tid is an integer in the range [0..(n-1)] which specifies **
** which of the n timers you are starting. **
** **
** To compute the duration of the event, just call **
** TM_ElapsedTime(tid), where tid is the same integer used in the **
** call to TM_StartTimer(). **
** **
** When you are finished with the timing routines, call TM_Close(). **
** This should fit in nicely with the cleanup section of your **
** application. **
** **
** If your application NEEDS to handle the time computations itself, **
** the function TM_ReadTimer(tid) is also available. This function **
** will return the current time (MOD 1 hour, approximately). I **
** discourage use of this function, but discovered that I need it **
** for another module/library... **
** **
** EXAMPLES **
** A simple delaying routine: **
** (TM_Init() must be called before this routine!) **
** void delay( tTIME duration ) **
** { **
** TM_StartTimer(0); **
** while (TM_ElapsedTime(0) < duration) **
** ; **
** } **
** **
** A fixed frame-rate game: **
** TM_Init(1); **
** while (player_not_dead) **
** { **
** TM_StartTimer(0); **
** MoveMonsters(); **
** MovePlayers(); **
** UpdateDisplay(); **
** while (TM_ElapsedTime(0) < frame_duration) **
** ; **
** } **
** TM_Close(); **
\***************************************************************************/
#ifndef __TIMER_H__
#define __TIMER_H__
/*------------------------------ Types ------------------------------------*/
/* type used to store time: should be 32-bits */
typedef unsigned long int tTIME;
/*----------------------------- Defines -----------------------------------*/
/* maximum number of timers to allow */
#define TM_MAX_TIMERS 1
/* just a handy constant */
#define ONE_SECOND 1193200 /* 65536(ticks/cycle) * 18.207(cycles/sec) */
/*------------------------- Public Prototypes -----------------------------*/
extern void TM_Close( );
extern tTIME TM_ElapsedTime( );
extern int TM_Init( );
extern tTIME TM_ReadTime( );
extern void TM_StartTimer( );
#endif /* __TIMER_H__ */